/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package feuerwehr;

import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author GundlaPe
 */
public class EinsatzTableModel extends AbstractTableModel {  
    String[] header = {"Einsatz-Nr", "Beginn", "Ende", "Strasse", "PLZ", "Ort", "Fahrzeuge", "Stichwort"}; 

    public EinsatzTableModel(List<EinsatzDaten> einsatzDaten) {
        this.einsatzDaten = einsatzDaten;
    }

    @Override
    public int getColumnCount() {
        return 8;
    }

    @Override
    public int getRowCount() {
        return einsatzDaten.size();
    }

    @Override
    public String getColumnName(int col) {
        return header[col];
    }

    @Override
    public Object getValueAt(int row, int col) {
        return einsatzDaten.get(row).getData(col);
    }

    @Override
    public Class getColumnClass(int c) {
        return new String().getClass();
    }
    
    public EinsatzDaten getEinsatzDaten(int row) {
        if (einsatzDaten.isEmpty()) 
            return null;
        return einsatzDaten.get(row);
    }

    /*
     * Don't need to implement this method unless your table's editable.
     */
    @Override
    public boolean isCellEditable(int row, int col) {
            return false;
    }

    /*
     * Don't need to implement this method unless your table's data can change.
     */
    @Override
    public void setValueAt(Object value, int row, int col) {
        // data[row][col] = value;
        fireTableCellUpdated(row, col);
    }
    
    private List<EinsatzDaten> einsatzDaten = null;
}
